<!DOCTYPE html>
<html>
	<head>
		<meta charset="utf-8">
		<title>JS的控制语句</title>
	</head>
	<body>
		<script type="text/javascript">
			/* 
				1、JS中的控制语句，和java相同，JS中除了java的控制语句之外，还有一些特别的：
					选择结构：
						if语句
						switch语句
					循环结构：
						for
						while
						do..while
					转向语句：
						break
						continue
						return
				2、JS有哪些特殊的语句呢？
					了解一下，不需要掌握：
						for..in 语句
						with    语句
			 */
			for(var i = 0; i < 10; i++){
				console.log("i = " + i)
			}
			
			var username = "";
			if(username) { // Boolean()函数
				console.log("welcome," + username)
			}else{
				console.log("username不能为空！")
			}
			
			// 数组(JS中的数组对象创建的时候使用的是：中括号)
			//var arr = [1,24,5,65,76,7];
			// 在JS的数组中数据的类型随意,可以不一致.
			var arr = [true,"abc",5,false,76,3.14];
			
			// 对数组遍历
			/* for(var i = 0; i < arr.length; i++){ //数组有length属性.
				console.log(arr[i])
			} */
			
			// for..in语句
			for(var fdsafdsafds in arr){ //arr是数组的话,fdsafdsafds就是数组的下标.
				//fdsafdsafds是数组的下标
				//console.log(fdsafdsafds)
				console.log(arr[fdsafdsafds])
			}
			
			// for..in语句还可以取对象的属性值.
			Employee = function(empno,ename){
				this.empno = empno;
				this.ename = ename;
			}
			
			var e = new Employee(7369, "SMITH");
			console.log(e.empno + "," + e.ename)
			console.log(e["empno"] + "," + e["ename"])
			
			// for..in语句遍历对象的属性
			for(var fdsafdsa in e){ // e是JS对象的话,fdsafdsa就是对象的属性名.并且属性名是字符串.
				//console.log(fdsafdsa)
				//console.log(typeof fdsafdsa) //string
				console.log(e[fdsafdsa])
				
				// 这种方式就不行了.
				//console.log(e.fdsafdsa)
			}
			
			var x = new Employee(7369, "SMITH");
			//console.log(x.empno + "," + x.ename)
			// with语句.
			with(x) {
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
				console.log(empno + "," + ename)
			}
			
		</script>
	</body>
</html>
